package com.example.springprincle.controller;

import com.example.springprincle.model.Doge;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class DogeController {
    @Autowired
    private ConfigurableApplicationContext context;
    @Autowired
    private Doge getDoge2;
    @Autowired
    private Doge getDoge3;
    @Autowired
    private Doge getDoge4;
    @Autowired
    private Doge getDoge5;
    @Autowired
    private Doge getDoge6;

    /**
     * 单例得到同一个对象
     * @return
     */
    @RequestMapping("/single")
    public String single(){
        //从context获取对象
        Doge contextDoge = context.getBean("getDoge2",Doge.class);
        return "contextDoge:"+contextDoge+"AutowiredDoge:"+getDoge2;
    }

    @RequestMapping("/prototype")
    public String prototype(){
        //从context获取对象
        Doge contextDoge = context.getBean("getDoge3",Doge.class);
        return "contextDoge:"+contextDoge+"<\br>AutowiredDoge:"+getDoge3;
    }

    @RequestMapping("/request")
    public String request(){
        //从context获取对象
        Doge contextDoge = context.getBean("getDoge4",Doge.class);
        return "contextDoge:"+contextDoge+"<\br>AutowiredDoge:"+getDoge4;
    }

    @RequestMapping("/session")
    public String session(){
        //从context获取对象
        Doge contextDoge = context.getBean("getDoge5",Doge.class);
        return "contextDoge:"+contextDoge+"<\br>AutowiredDoge:"+getDoge5;
    }
    @RequestMapping("/application")
    public String application(){
        //从context获取对象
        Doge contextDoge = context.getBean("getDoge6",Doge.class);
        return "contextDoge:"+contextDoge+"<\br>AutowiredDoge:"+getDoge6;
    }
}
